import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

showActionSheet({required List<String> titles, Function(int)? onTap}) {
  if (Get.context == null) {
    return;
  }
  var _query = MediaQuery.of(Get.context!);
  showModalBottomSheet(
      context: Get.context!,
      constraints: BoxConstraints.expand(
          height: titles.length * 50.r + _query.padding.bottom),
      builder: (context) {
        return ListView(
          children: titles
              .asMap()
              .map(
                (key, value) => MapEntry(
                  key,
                  GestureDetector(
                    onTap: () {
                      Navigator.of(context).pop();
                      if (onTap != null) {
                        onTap(key);
                      }
                    },
                    child: Container(
                      height: 50.r,
                      width: double.infinity,
                      decoration: const BoxDecoration(
                          border: Border(
                              bottom: BorderSide(
                                  color: Color(0xffeeeeee), width: 1))),
                      alignment: Alignment.center,
                      child: Text(
                        value,
                        style: TextStyle(
                            color: const Color(0xff333333), fontSize: 14.sp),
                      ),
                    ),
                  ),
                ),
              )
              .values
              .toList(),
        );
      });
}
